package com.opgea.crm.repository;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.opgea.crm.domain.entities.AdditionalContact;

@Repository
public class AddtionalContactRepoImpl implements AdditionalContactRepo{

	@PersistenceContext
	private EntityManager em;
	
	@Override
	public void create(AdditionalContact addtionalContact) {
		em.persist(addtionalContact);
	}

	@Override
	public void remove(long contactId) {
		em.remove(this.find(contactId));
	}

	@Override
	public AdditionalContact find(long contactId) {
		return em.find(AdditionalContact.class, contactId);
	}

	@Override
	public List<AdditionalContact> findAll() {
		String query = "SELECT a FROM AdditionalContact a ";
		return em.createQuery(query, AdditionalContact.class).getResultList();
	}

	@Override
	public List<AdditionalContact> findAllByLeadId(long leadId) {
		String query = "SELECT a FROM AdditionalContact a WHERE a.lead.id = "+leadId;
		return em.createQuery(query, AdditionalContact.class).getResultList();
	}

}
